/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ListaActualizaciones.java
 *
 * Created on 17-ene-2013, 17:55:58
 */
package gui;

import com.sun.awt.AWTUtilities;
import io.Caso;
import io.Intervencion;
import io.IntervencionAdiccion;
import io.IntervencionComun;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;
import utilidades.JFrameConFondo;

/**
 *
 * @author NiCo
 */
public class ListaIntervenciones extends JFrameConFondo {

    private Image icono = new ImageIcon(getClass().getResource("/imagenes/logo.png")).getImage();
    private SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("HH:mm");
    private final char donde;

    /** Creates new form ListaActualizaciones */
    public ListaIntervenciones(Caso caso, char donde) {
        initComponents();
        Iterator<Intervencion> it = caso.getIntervenciones().iterator();
        Object[] obj;
        DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
        while (it.hasNext()) {
            Intervencion seg = it.next();
            obj = new Object[2];
            obj[0] = seg;
            try {
                IntervencionAdiccion aux = (IntervencionAdiccion) seg;
                obj[1] = "Adicción";
            } catch (Exception e) {
            }
            try {
                IntervencionComun aux = (IntervencionComun) seg;
                obj[1] = "Violencia";
            } catch (Exception e) {
            }
            modelo.addRow(obj);
        }
        this.donde = donde;
        if (donde == 'c') {
            jLabel2.setText("Seleccione una intervención de la lista");
        } else {
            if (donde == 'e') {
                jLabel2.setText("Seleccione una intervencion de la lista para eliminar");
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnCerrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png"))); // NOI18N
        btnCerrar.setBorder(null);
        btnCerrar.setBorderPainted(false);
        btnCerrar.setFocusPainted(false);
        btnCerrar.setName("btnCerrar"); // NOI18N
        btnCerrar.setOpaque(false);
        btnCerrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btnCerrarMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btnCerrarMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnCerrarMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btnCerrarMouseReleased(evt);
            }
        });
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/titulo-lista-intervenciones.png"))); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Seleccione una intervención para modificar"); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/seleccionar.png"))); // NOI18N
        jButton1.setBorderPainted(false);
        jButton1.setFocusPainted(false);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Fecha", "Tipo de intervención"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(73, 73, 73)
                        .addComponent(btnCerrar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(131, 131, 131)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnCerrar)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseEntered

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-activo.png")));     }//GEN-LAST:event_btnCerrarMouseEntered

    private void btnCerrarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseExited

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png")));     }//GEN-LAST:event_btnCerrarMouseExited

    private void btnCerrarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMousePressed

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-click.png")));     }//GEN-LAST:event_btnCerrarMousePressed

    private void btnCerrarMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseReleased

        btnCerrar.setIcon(new ImageIcon(getClass().getResource("/imagenes/cerrar-normal.png")));     }//GEN-LAST:event_btnCerrarMouseReleased

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (donde == 'b') {
            Intervencion act = (Intervencion) jTable1.getValueAt(jTable1.getSelectedRow(), 0);
            ModificarIntervencion frm = new ModificarIntervencion(act);
            frm.setLocationRelativeTo(null);
            frm.setImagen("/imagenes/fondo.png");
            frm.setIconImage(icono);
            frm.setVisible(true);
            Shape shape = new RoundRectangle2D.Float(0, 0, frm.getWidth(), frm.getHeight(), 30, 30);
            AWTUtilities.setWindowShape(frm, shape);
        } else {
            if (donde == 'c') {
                Intervencion act = (Intervencion) jTable1.getValueAt(jTable1.getSelectedRow(), 0);
                ConsultarIntervencion frm = new ConsultarIntervencion(act);
                frm.setLocationRelativeTo(null);
                frm.setImagen("/imagenes/fondo.png");
                frm.setIconImage(icono);
                frm.setVisible(true);
                Shape shape = new RoundRectangle2D.Float(0, 0, frm.getWidth(), frm.getHeight(), 30, 30);
                AWTUtilities.setWindowShape(frm, shape);
            } else {
                if (donde == 'e') {
                    Intervencion act = (Intervencion) jTable1.getValueAt(jTable1.getSelectedRow(), 0);
                    EliminarIntervencion frm = new EliminarIntervencion(act);
                    frm.setLocationRelativeTo(null);
                    frm.setImagen("/imagenes/fondo.png");
                    frm.setIconImage(icono);
                    frm.setVisible(true);
                    Shape shape = new RoundRectangle2D.Float(0, 0, frm.getWidth(), frm.getHeight(), 30, 30);
                    AWTUtilities.setWindowShape(frm, shape);
                }
            }
        }
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
